import itertools

def avg(x):
    return sum(x)/(len(x) or 1)

def cov(x, y):
    return avg([p * q for p, q in zip(x, y)]) - avg(x) * avg(y)

def var(x):
    return cov(x, x)

def with_counter(x):
    return itertools.izip(itertools.count(), x)

def ranks(x):
    pairs = sorted(itertools.izip(x, itertools.count()))
    out = [0] * len(x)
    prev = None
    ixs = []
    for rk, (num, ix) in with_counter(pairs):
        if num == prev:
            ixs.append(ix)
        else:
            adj = 2 * rk - len(ixs)
            for i in ixs:
                out[i] = adj
            prev = num
            ixs = [ix]
    adj = 2 * len(x) - len(ixs)
    for i in ixs:
        out[i] = adj
    return out
